/** @format */
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = {
  mode: 'development',

  cache: {
    type: 'filesystem',
    //  
    buildDependencies: {
      // 当该文件被修改时
      config: [__filename],
    },
  },
  devServer:{
    port: 8888,
    open: true,
    client: {
      progress: true,
      overlay: false,
    },
  },
  entry: './src/index.tsx',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].[chunkhash:8].js',
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, './public/index.html'),
    }),
    new MiniCssExtractPlugin({
      filename: '[name].css'
    })

  ],
  module: {
    rules: [
      {
        test: /\.(tsx?|js)$/,
        // options: { cacheDirectory: true },
        include: path.resolve(__dirname, "src"),
        use: [
          // "thread-loader",
          'babel-loader',
          // 耗时的 loader （例如 babel-loader）
        ],
      },
      // 本地模块化 less
      {
        test: /\.less$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'less-loader'
        ]
      },

      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader']
      },

      // 图片处理
      {
        test: /\.(png|jpg|gif)$/,
        type: 'asset'
      },
      {
        test: /\.(woff|woff2|eot|ttf|svg)$/,
        type: 'asset/resource'
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.json'],
    alias: {
      'react-dom': '@hot-loader/react-dom',
      pages: path.join(__dirname, 'src/pages'),
      Components: path.join(__dirname, 'src/components'),
      widget: path.join(__dirname, 'src/widget'),
      router: path.join(__dirname, 'src/router'),
      utils: path.join(__dirname, 'src/utils'),
      assets: path.join(__dirname, 'src/assets'),
      themes: path.join(__dirname, 'src/themes'),
      config: path.join(__dirname, 'src/config')
    }
  },
  mode: 'development'
};
